package indi.zhifa.recipe.bailan.framework.enums.controller.api;

import indi.zhifa.recipe.bailan.framework.common.entity.annotations.ZfRestController;
import indi.zhifa.recipe.bailan.framework.enums.entity.dto.*;
import indi.zhifa.recipe.bailan.framework.enums.entity.po.SysTypeItemEntity;
import indi.zhifa.recipe.bailan.framework.enums.entity.vo.SysTypeVo;
import indi.zhifa.recipe.bailan.framework.enums.service.ITypeMgrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Api(tags = "1.后台类型管理")
@RequestMapping("/api/mgr/types")
@Slf4j
@ZfRestController
@RequiredArgsConstructor
public class SysTypeApi {

    final ITypeMgrService mTypeMgrService;

    @Operation(summary = "创建类型")
    @PostMapping("")
    SysTypeVo create( @Parameter(description = "类型配置") @RequestBody SysTypeCreateDto pSysTypeCfg){
        SysTypeVo sysTypeVo = mTypeMgrService.create(pSysTypeCfg);
        return sysTypeVo;
    }

    @Operation(summary = "修改类型")
    @PutMapping ("/{id}")
    SysTypeVo edit(
            @Parameter(description = "类型Id") @PathVariable(name = "id") Long pId,
            @Parameter(description = "类型配置") @RequestBody SysTypeEditDto pSysTypeEditCfg){
        SysTypeVo sysTypeVo = mTypeMgrService.edit(pId,pSysTypeEditCfg);
        return sysTypeVo;
    }

    @Operation(summary = "修改类型-全")
    @PutMapping ("/{id}/whole")
    SysTypeVo edit(
            @Parameter(description = "类型Id") @PathVariable(name = "id") Long pId,
            @Parameter(description = "类型配置") @RequestBody SysTypeEditAllDto pSysTypeEditCfg){
        SysTypeVo sysTypeVo = mTypeMgrService.edit(pId,pSysTypeEditCfg);
        return sysTypeVo;
    }



    @Operation(summary = "查询类型")
    @GetMapping ("/{id}")
    SysTypeVo info(
            @Parameter(description = "类型Id") @PathVariable(name = "id") Long pId){
        SysTypeVo sysTypeVo = mTypeMgrService.info(pId);
        return sysTypeVo;
    }

    @Operation(summary = "查询类型-code")
    @GetMapping ("/code/{code}")
    SysTypeVo info(
            @Parameter(description = "类型Id") @PathVariable(name = "code") String pCode){
        SysTypeVo sysTypeVo = mTypeMgrService.info(pCode);
        return sysTypeVo;
    }


    @Operation(summary = "添加类型项")
    @PostMapping ("/{typeId}/items/create")
    SysTypeItemEntity addItem(
            @Parameter(description = "类型Id") @PathVariable(name = "typeId") Long pTypeId,
            @Parameter(description = "类型项配置") @RequestBody SysTypeItemCreateDto pSysTypeItemCreateCfg){
        SysTypeItemEntity sysTypeItemEntity = mTypeMgrService.addItem(pTypeId,pSysTypeItemCreateCfg);
        return sysTypeItemEntity;
    }

    @Operation(summary = "修改类型项")
    @PostMapping ("/{typeId}/items/{id}")
    SysTypeItemEntity editItem(
            @Parameter(description = "类型Id") @PathVariable(name = "id") Long pId,
            @Parameter(description = "类型项配置") @RequestBody SysTypeItemEditDto pSysTypeItemEditCfg){
        SysTypeItemEntity sysTypeItemEntity = mTypeMgrService.editItem(pId,pSysTypeItemEditCfg);
        return sysTypeItemEntity;
    }

    @DeleteMapping ("/{id}")
    @Operation(summary = "删除类型")
    Boolean deleteTypeItem(
            @Parameter(description = "类型Id") @PathVariable(name = "id") Long pId){
        return mTypeMgrService.deleteType(pId);
    }

    @DeleteMapping ("/items/{id}")
    @Operation(summary = "删除类型项")
    boolean deleteType(
            @Parameter(description = "类型Id") @PathVariable(name = "id") Long pId){
        return mTypeMgrService.deleteTypeItem(pId);
    }
}
